package com.yyjj.hangqing.fragment;

import android.os.Bundle;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.hangqing.R;
import com.yyjj.hangqing.adapter.FundListAdapter;
import com.yyjj.hangqing.adapter.YouXuanAdapter;
import com.yyjj.hangqing.api.Api;
import com.yyjj.hangqing.entity.BaseTResp;
import com.yyjj.hangqing.entity.FundEntity;
import com.yyjj.hangqing.entity.YouXuanEntity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadFragment;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.view.SpaceItemDecoration;

/**
 * 首页热门推荐
 */
public class HomeHotListFragment extends BaseRefreshLoadFragment{

    public static HomeHotListFragment newInstance(String title) {
        Bundle args = new Bundle();
        args.putString("type",title);
        HomeHotListFragment fragment = new HomeHotListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getContentLayout() {
        return R.layout.hq_refresh_notitle;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mRecyclerView.setNestedScrollingEnabled(false);
        loadData();
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new YouXuanAdapter(R.layout.hq_item_youxuan);
    }

    @Override
    public void loadData(int page) {

        ViseHttp.GET(Api.YOUXUAN_URL)
                .baseUrl(ApiConstant.BASE_URL)
                .request(new ACallback<tech.com.commoncore.entity.BaseTResp<ArrayList<YouXuanEntity>>>() {

                    @Override
                    public void onSuccess(tech.com.commoncore.entity.BaseTResp<ArrayList<YouXuanEntity>> data) {
                        if ((1 == data.code) && (data.data != null)) {
                            if (data.data.size()>=3){
                                FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),data.data.subList(0,3),null);
                            }else {
                                FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),data.data,null);
                            }

                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        FastManager.getInstance().getHttpRequestControl().httpRequestError(getIHttpRequestControl(), errCode + "", errMsg);
                    }
                });
    }

    @Override
    public boolean isRefreshEnable() {
        return false;
    }

    @Override
    public boolean isLoadMoreEnable() {
        return false;
    }
}
